package com.czg.jsonschema2lombokpojo.annotator;

import com.czg.jsonschema2lombokpojo.config.GenerationConfig;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JEnumConstant;
import com.sun.codemodel.JFieldVar;

/**
 * 使用Moshi注解生成的Java类型。当JSON字段包含不适合bean使用的字符（如下划线）时，这里使用的注解最有用。通过使用Moshi ‘Json’注解，我们能够保留原始格式。
 *
 * @see <a
 *      href="https://github.com/square/moshi#custom-field-names-with-json">https://github.com/square/moshi#custom-field-names-with-json</a>
 */
public class Moshi1Annotator extends AbstractAnnotator {

    public Moshi1Annotator(GenerationConfig generationConfig) {
        super(generationConfig);
    }

    @Override
    public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) {
        JClass moshiAnnotation = clazz.owner().directClass("com.squareup.moshi.Json");
        field.annotate(moshiAnnotation).param("name", propertyName);
    }

    @Override
    public void enumConstant(JDefinedClass _enum, JEnumConstant constant, String value) {
        JClass moshiAnnotation = _enum.owner().directClass("com.squareup.moshi.Json");
        constant.annotate(moshiAnnotation).param("name", value);
    }

    @Override
    public boolean isAdditionalPropertiesSupported() {
        return false;
    }

}
